home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Dogs / Multimedia Dogs v2.0.iso / mac / Multimedia Dogs 2.0 / MMDOGS2.DXR / 00280_Chapter handlers.ls < prev    next >
Encoding:
Text File  |  1995-10-09  |  10.0 KB  |  280 lines

  1. global gCDvolume, gCPU, gMiscXObjName, gJumpMarker, gpChapterTextSprite, gpChapterMarker, gpChapterDatabase, gpChapterDatabaseCount, gpTopicsVideoDatabase, gpTopicsVideoDatabaseCount, gpChapterTitleCastnum, gpChapterTextNormalColor, gpChapterTextHiliteColor, gpChapterTextFlashColor, gpChapterTextPath, gpChapterVideoPath, gpLastString, gpLastOffset, gpChapterIndex
  2.  
  3. on initChapter
  4.   initChapterDatabase()
  5.   initTopicsVideoDatabase()
  6.   set gpChapterIndex to 0
  7.   set gpChapterTextSprite to 23
  8.   set gpChapterMarker to "chapter"
  9.   set gpChapterTitleCastnum to the number of cast "ChapterTitle"
  10.   set gpChapterTextNormalColor to the foreColor of cast "ChapterNormalColor"
  11.   set gpChapterTextHiliteColor to the foreColor of cast "ChapterHiliteColor"
  12.   set gpChapterTextFlashColor to the foreColor of cast "ChapterFlashColor"
  13.   set gpLastString to EMPTY
  14.   set gpLastOffset to 0
  15.   if gCPU = #mac then
  16.     set gpChapterTextPath to gCDvolume & ":data:topics:text:"
  17.     set gpChapterVideoPath to gCDvolume & ":data:topics:video:"
  18.   else
  19.     set gpChapterTextPath to gCDvolume & "\data\topics\text\"
  20.     set gpChapterVideoPath to gCDvolume & "\data\topics\video\"
  21.   end if
  22. end
  23.  
  24. on initChapterDatabase
  25.   set gpChapterDatabase to ["getting": "Choosing a Dog", "home": "Bringing Your Dog Home", "training": "Training & Obedience", "feeding": "Feeding & Nutrition", "grooming": "Grooming", "healthy": "Preventative Care", "illness": "Illnesses & Ailments", "medical": "Medical Treatment", "work": "Dogs at Work", "shows": "Dog Shows", "travel": "Travel & Boarding", "evolutio": "Evolution", "anatomy": "Anatomy", "behavior": "Behavior", "breeding": "Breeding"]
  26.   set gpChapterDatabaseCount to count(gpChapterDatabase)
  27. end
  28.  
  29. on initTopicsVideoDatabase
  30.   set gpTopicsVideoDatabase to ["Advanced Obedience and Stunts": "stunts", "Animal Shelters": "shelter", "Brushing Your Dog": "brushing", "Canine Companions for Independence": "cci", "Cleaning the Eyes and Ears of a Dog": "eyesears", "Dogs as Police Assistants": "police", "Dogs Herding": "herding", "Dogs Hunting": "hunting", "Guide Dogs for the Blind": "guide", "High-Flying Dogs": "flying", "Land Rescue": "landresc", "Obedience": "obedienc", "Schutzhund": "schutz", "Sledding Activities": "sledding", "Teaching Your Dog to Come": "come", "Teaching Your Dog to Lie Down": "down", "Teaching Your Dog to Heel": "heel", "Teaching Your Dog to Sit": "sit", "Teaching Your Dog to Stay": "stay", "Water Rescue": "waterres", "Your Dog's Teeth": "teeth"]
  31.   set gpTopicsVideoDatabaseCount to count(gpTopicsVideoDatabase)
  32. end
  33.  
  34. on enterChapter
  35.   setHelpContext("topics")
  36.   setTopicsMarker(getChapterMarker())
  37.   safePuppetSprite(gpChapterTextSprite, 1)
  38.   setChapter(gpChapterIndex)
  39.   set gpLastOffset to 0
  40. end
  41.  
  42. on exitChapter
  43.   puppetSprite(gpChapterTextSprite, 0)
  44. end
  45.  
  46. on getChapterMarker
  47.   return gpChapterMarker
  48. end
  49.  
  50. on handleChapterSelection theSprite
  51.   set theCode to the name of cast castNumOfSprite(theSprite)
  52.   set gpChapterIndex to findPos(gpChapterDatabase, theCode)
  53.   set gJumpMarker to getChapterMarker()
  54.   go(the frame + 1)
  55. end
  56.  
  57. on handleChapterNext
  58.   if gpChapterIndex = gpChapterDatabaseCount then
  59.     set gJumpMarker to getGlossaryMarker()
  60.     set gpChapterIndex to gpChapterIndex + 1
  61.     go(the frame + 1)
  62.     exit
  63.   end if
  64.   if getTopicsMarker() = getTOCMarker() then
  65.     set gJumpMarker to getChapterMarker()
  66.     set gpChapterIndex to 1
  67.     go(the frame + 1)
  68.     exit
  69.   end if
  70.   set gpChapterIndex to gpChapterIndex + 1
  71.   set gJumpMarker to getChapterMarker()
  72.   go(the frame + 1)
  73. end
  74.  
  75. on handleChapterPrev
  76.   if gpChapterIndex = 1 then
  77.     set gJumpMarker to getTOCMarker()
  78.     go(the frame + 1)
  79.     exit
  80.   end if
  81.   if getTopicsMarker() = getGlossaryMarker() then
  82.     set gJumpMarker to getChapterMarker()
  83.     set gpChapterIndex to gpChapterDatabaseCount
  84.     go(the frame + 1)
  85.     exit
  86.   end if
  87.   set gpChapterIndex to gpChapterIndex - 1
  88.   set gJumpMarker to getChapterMarker()
  89.   go(the frame + 1)
  90. end
  91.  
  92. on setChapter theIndex
  93.   set theFileCode to getPropAt(gpChapterDatabase, theIndex)
  94.   set theCastnum to the number of cast (theFileCode & ".txt")
  95.   set the castNum of sprite gpChapterTextSprite to theCastnum
  96.   put EMPTY before char 1 of field theCastnum
  97.   set theTitle to gpChapterIndex & "." && getaProp(gpChapterDatabase, theFileCode)
  98.   set the text of cast gpChapterTitleCastnum to theTitle
  99. end
  100.  
  101. on handleChapterSearch
  102.   waitCursor()
  103.   set theCastnum to castNumOfSprite(gpChapterTextSprite)
  104.   set theText to the text of cast theCastnum
  105.   set totalChars to length(theText)
  106.   openXLib(gMiscXObjName)
  107.   set dialog to MISC_X(mnew)
  108.   pointerCursor()
  109.   if not objectp(dialog) then
  110.     alert("Sorry - Cannot create Search dialog.")
  111.     return 
  112.   end if
  113.   set theMsg to "Enter the word or phrase that you would like to find in this chapter."
  114.   set searchString to dialog(mAsk, theMsg, gpLastString, "Find", "Cancel")
  115.   updateStage()
  116.   if searchString = "Cancel" then
  117.     closeXLib(gMiscXObjName)
  118.     exit
  119.   end if
  120.   autoWaitCursor()
  121.   if searchString <> gpLastString then
  122.     set gpLastString to searchString
  123.     set gpLastOffset to 0
  124.   end if
  125.   set theOffset to offset(searchString, char gpLastOffset + 1 to totalChars of theText)
  126.   if theOffset = 0 then
  127.     set gpLastOffset to 0
  128.     set theOffset to offset(searchString, char gpLastOffset + 1 to totalChars of theText)
  129.     if theOffset = 0 then
  130.       alert("Could not find" && QUOTE & searchString & QUOTE && "in this chapter.")
  131.       dialog(mdispose)
  132.       closeXLib(gMiscXObjName)
  133.       exit
  134.     end if
  135.   end if
  136.   set theOffset to gpLastOffset + theOffset
  137.   set gpLastOffset to theOffset
  138.   set thePoint to min(theOffset + 100, the number of chars in field theCastnum)
  139.   put EMPTY before char thePoint of field theCastnum
  140.   flashChunk(theCastnum, theOffset, theOffset + length(searchString) - 1, gpChapterTextFlashColor)
  141.   dialog(mdispose)
  142.   closeXLib(gMiscXObjName)
  143. end
  144.  
  145. on flashChunk theCastnum, first, last, theColor
  146.   set theHiliteColor to theColor
  147.   set theNormalColor to the foreColor of char first of cast theCastnum
  148.   repeat with i = 1 to 3
  149.     set the foreColor of char first to last of cast theCastnum to theHiliteColor
  150.     delayTicks(10)
  151.     set the foreColor of char first to last of cast theCastnum to theNormalColor
  152.   end repeat
  153. end
  154.  
  155. on handleChapterVideoList
  156.   set theString to EMPTY
  157.   repeat with i = 1 to gpTopicsVideoDatabaseCount - 1
  158.     set theString to theString & getPropAt(gpTopicsVideoDatabase, i) & RETURN
  159.   end repeat
  160.   set theString to theString & getPropAt(gpTopicsVideoDatabase, gpTopicsVideoDatabaseCount)
  161.   set theCallback to "tell the stage to openChapterVideo(theIndex)"
  162.   openSelectionMIAW(theString, "Select A Video", theCallback)
  163. end
  164.  
  165. on handleChapterPrint
  166.   set theAnswer to confirm("Would you like to print the text for this chapter?")
  167.   if theAnswer = 0 then
  168.     exit
  169.   end if
  170.   waitCursor()
  171.   puppetSound("printing.aif")
  172.   updateStage()
  173.   set theTitle to the text of cast gpChapterTitleCastnum
  174.   printText(the text of cast castNumOfSprite(gpChapterTextSprite), theTitle)
  175.   pointerCursor()
  176. end
  177.  
  178. on handleChapterHyperLink
  179.   set theKey to extractKeyFromHyperLink()
  180.   if voidp(theKey) then
  181.     exit
  182.   end if
  183.   autoWaitCursor()
  184.   closeAllMIAWs()
  185.   set theIndex to findPos(gpTopicsVideoDatabase, theKey)
  186.   if voidp(theIndex) then
  187.     alert("Cannot find movie in the database:" && theKey)
  188.     exit
  189.   end if
  190.   openChapterVideo(theIndex)
  191. end
  192.  
  193. on openChapterVideo theIndex
  194.   set theFileCode to getAt(gpTopicsVideoDatabase, theIndex)
  195.   set theTitle to getPropAt(gpTopicsVideoDatabase, theIndex)
  196.   set theFilename to gpChapterVideoPath & theFileCode & ".mov"
  197.   openVideoMIAW(theFilename, theTitle)
  198. end
  199.  
  200. on extractKeyFromHyperLink
  201.   if the mouseWord = -1 then
  202.     exit
  203.   end if
  204.   set theTextCast to the castNum of sprite the clickOn
  205.   set theSelectColor to the foreColor of word the mouseWord of cast theTextCast
  206.   putDebug("mouseWord =" && the mouseWord && word the mouseWord of the text of cast theTextCast)
  207.   if theSelectColor <> gpChapterTextHiliteColor then
  208.     exit
  209.   end if
  210.   set theIndex to the mouseChar
  211.   set theChar to char theIndex of the text of cast theTextCast
  212.   repeat while theChar <> "["
  213.     set theIndex to theIndex - 1
  214.     set theChar to char theIndex of the text of cast theTextCast
  215.   end repeat
  216.   set theKey to EMPTY
  217.   set theIndex to theIndex + 17
  218.   set theChar to char theIndex of the text of cast theTextCast
  219.   repeat while theChar <> QUOTE
  220.     set theKey to theKey & theChar
  221.     set theIndex to theIndex + 1
  222.     set theChar to char theIndex of the text of cast theTextCast
  223.   end repeat
  224.   putDebug("theKey =" && theKey)
  225.   return theKey
  226. end
  227.  
  228. on genTopicsText
  229.   if the colorDepth <> 8 then
  230.     alert("Color depth must be 8-bit to generate Topics text!")
  231.     exit
  232.   end if
  233.   put "Generating Topics text..."
  234.   initChapter()
  235.   repeat with i = 1 to gpChapterDatabaseCount
  236.     set theTopicCode to getPropAt(gpChapterDatabase, i)
  237.     loadChapterText(theTopicCode)
  238.     markChapterText(theTopicCode)
  239.   end repeat
  240.   put "Done."
  241.   beep()
  242.   alert("CHECK FOR EXTRA RETURNS AT END OF TEXT!!!")
  243. end
  244.  
  245. on loadChapterText theTopicCode
  246.   set theTextPath to "DogDisc:data:zsupport:text:"
  247.   set theFilename to theTextPath & theTopicCode & ".txt"
  248.   put "reading" && theFilename
  249.   set file to FileIO(mnew, "read", theFilename)
  250.   if not objectp(file) then
  251.     alert("Cannot read file:" && theFilename)
  252.     set the text of cast theTopicCode to " "
  253.     exit
  254.   end if
  255.   set the text of cast (theTopicCode & ".txt") to file(mReadFile)
  256.   updateStage()
  257. end
  258.  
  259. on markChapterText theTopicCode
  260.   put "marking" && theTopicCode
  261.   set theCastName to theTopicCode & ".txt"
  262.   set theText to the text of cast theCastName
  263.   set totalChars to length(theText)
  264.   set startString to "[Click here"
  265.   set endString to "]"
  266.   set theLastOffset to 0
  267.   repeat while 1
  268.     set theOffset to offset(startString, char theLastOffset + 1 to totalChars of theText)
  269.     if theOffset = 0 then
  270.       exit repeat
  271.     end if
  272.     set theOffset to theOffset + theLastOffset
  273.     set theLastOffset to theOffset
  274.     set theOffset to offset(endString, char theLastOffset + 1 to totalChars of theText)
  275.     set theOffset to theOffset + theLastOffset
  276.     set the foreColor of char theLastOffset to theOffset of cast theCastName to 5
  277.     set theLastOffset to theOffset
  278.   end repeat
  279. end
  280.